
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

/**
 * @author sjw
 * @className AskThread
 * @date 2022/5/2 16:38
 * @description: TODO
 */
public class AskThread implements Runnable {
    private CompletableFuture<Integer> re = null;

    @Override
    public void run() {
        int res = 0;
        try {
            System.out.println("--1--");
            res = re.get() * re.get();
            System.out.println("--2--");
        } catch (ExecutionException | InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(res);
    }

    public AskThread(CompletableFuture<Integer> re) {
        this.re = re;
    }

    public static void main(String[] args) throws InterruptedException {
        final CompletableFuture<Integer> future = new CompletableFuture<>();
        new Thread(new AskThread(future)).start();
        Thread.sleep(1000);
        System.out.println("==1");
        future.complete(10);
        System.out.println("==2");
    }

}
